7. Reverse Integer
마지막 수정일: 2025. 05. 21.
간단한 js에서 string - number 처리 문제
문제 주소
자료형 크기를 c++에서만 해보다 js에서 해보니 색달랐음
var reverse = function(x) {
let stringX = String(x)
let minus = false;
if(stringX[0] === "-"){
stringX = stringX.substring(1)
minus = true;
}
stringX = stringX.split("").reverse().join("");
const res = parseInt(minus ? "-" + stringX: stringX)
return (res > Math.pow(2,31) -1 || res< Math.pow(-2, 31)) ? 0: res
};